Skip to main content
ICT
Lesson A20 - Inheritance, Polymorphism, and Abstract Classes
 
Main Previous Next
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
 

A. Inheritance page 3 of 8

  1. A key element in Object Oriented Programming (OOP) is the ability to derive new classes from existing classes by adding new methods and redefining existing methods. The new class can inherit many of its attributes and behaviors from the existing class. This process of deriving new classes from existing classes is called inheritance, which was introduced in Lesson A11, Inheritance.

The more general class that forms the basis for inheritance is called the superclass. The more specialized class that inherits from the superclass is called the subclass (or derived class).

  1. In Java, all classes belong to one big hierarchy derived from the most basic class, called Object. This class provides a few features common to all objects; more importantly, it makes sure that any object is an instance of the Object class, which is useful for implementing structures that can deal with any type of object. If we start a class from “scratch,” the class automatically extends Object. For example:

    public class SeaCreature{
    ...
    }

    is equivalent to:

    public class SeaCreature extends Object{
    ...
    }

    when new classes are derived from SeaCreature, a class hierarchy is created. For example:

    public class Fish extends SeaCreature{
    ...
    }

    public class Mermaid extends SeaCreature{
    ...
    }

    This results in the hierarchy shown below.


Figure 20-1. SeaCreature and two derived classes

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.